package com.tenqian.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

public class LogHandler extends HandlerInterceptorAdapter {
    Logger logger = LoggerFactory.getLogger(LogHandler.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        logger.info("uri:{}", request.getRequestURI());
        logger.info("method:{}", request.getMethod());
        Map<String, String[]> parameterMap = request.getParameterMap();
        logger.info("parameters:");
        for (String o : parameterMap.keySet()) {
            logger.info(o + ":{}", parameterMap.get(o)[0]);
        }
        return true;
    }
}
